﻿Public Class PropertyValidator
    Public Sub ResetControls(ByVal grp As GroupBox)
        For Each ctl In grp.Controls
            If TypeOf ctl Is TextBox Then
                ctl.Text = ""
            ElseIf TypeOf ctl Is ListView Then
                CType(ctl, ListView).Items.Clear()
            End If
        Next ctl
    End Sub
    Public Sub resizes(ByVal lvwResize As ListView)
        Dim col As Integer
        For col = 1 To lvwResize.Columns.Count
            lvwResize.AutoResizeColumn(col - 1, ColumnHeaderAutoResizeStyle.HeaderSize)
            'lvwResize.AutoResizeColumn(col - 1, ColumnHeaderAutoResizeStyle.ColumnContent)
        Next
    End Sub

    Public Function IsEnteredInTheComboBoxList(ByVal cboBox As ComboBox, ByVal fieldName As String)
        If cboBox.Text = "" Then
            MessageBox.Show("Please choose a valid " + fieldName.Trim())
            HighlightControl(cboBox)
            Return True
        Else
            Return False
        End If
    End Function
    Public Function IsEmptyString(ByVal txtBox As TextBox, ByVal fieldName As String)
        If txtBox.Text = "" Then
            MessageBox.Show(fieldName.Trim() + " should not be left blank.")
            HighlightControl(txtBox)
            Return True
        Else
            Return False
        End If
    End Function
    Public Function IsNumericString(ByVal txtBox As TextBox, ByVal fieldName As String) As Boolean
        If txtBox.Text = "" Then
            MessageBox.Show(fieldName.Trim() + " should not be left blank.")
            HighlightControl(txtBox)
            Return True
        ElseIf IsNumeric(txtBox.Text) = False Then
            MessageBox.Show(fieldName.Trim() + " should be numeric.")
            HighlightControl(txtBox)
            Return True
        Else
            Return False
        End If
    End Function
    Public Function IsTimeString(ByVal txtBox As TextBox, ByVal fieldName As String) As Boolean
        If txtBox.Text = "" Then
            MessageBox.Show(fieldName.Trim() + " should not be left blank.")
            HighlightControl(txtBox)
            Return True
        ElseIf IsNumeric(txtBox.Text.Replace(":", "")) = False Then
            MessageBox.Show(fieldName.Trim() + " should be numeric.")
            HighlightControl(txtBox)
            Return True
        Else
            Return False
        End If
    End Function
    Public Sub HighlightControl(ByVal txtBox As TextBox)
        txtBox.Focus()
        txtBox.SelectAll()
    End Sub
    Public Sub HighlightControl(ByVal cboBox As ComboBox)
        cboBox.Focus()
        cboBox.SelectAll()
    End Sub
End Class
